﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Configuration;
using DTO;
using Moved;
namespace BUS
{
    public class RolesBUS
    {
        private static string _connectstring;
        static RolesBUS()
        {
            _connectstring = ConfigurationManager.ConnectionStrings["WebChamCongConnectionString"].ConnectionString.ToString();
        }
        public static List<DTO.RoleDTO> getRole()
        {
            List<DTO.RoleDTO> _listRole = new List<RoleDTO>();
            using (Moved.Moved_DB dc = new Moved_DB(_connectstring))
            {
                var objRole = (from Rl in dc.WIT_Roles
                               select new 
                               { 
                                   idRole=Rl.ID,
                                   userRole=Rl.UserRole,
                                   RoleDS=Rl.RoleDescription
                               }
                               ).Distinct();
                foreach (var kq in objRole)
                {
                    DTO.RoleDTO r = new RoleDTO();
                    r.IdRole = kq.idRole;
                    r.UserRoles = kq.userRole;
                    r.RoleDescription = kq.RoleDS;
                    _listRole.Add(r);
                }
                return _listRole;
            }
        }
        public static DTO.RoleDTO getRoleByID(int id)
        {
            int localID = id;
            DTO.RoleDTO role = null;
            using (Moved.Moved_DB dc = new Moved_DB(_connectstring))
            {
                var objRole = (from rl in dc.WIT_Roles
                               where rl.ID == id
                               select new 
                               {
                                   idRole = rl.ID,
                                   userRole = rl.UserRole,
                                   RoleDS = rl.RoleDescription
                               });
                foreach (var kq in objRole)
                {
                    role = new RoleDTO();
                    role.IdRole = kq.idRole;
                    role.UserRoles = kq.userRole;
                    role.RoleDescription = kq.RoleDS;
                }
                return role;
            }
        }

    }
}
